<?php  
$page_title = "Fifaonline.ro | Campionate fifa virtuale | Stiri sportive";
include_once("top.php"); 

if (!isset($_SESSION['identitate']))
{
	header("Location: http://localhost/polls.php");
	exit();
}

if(isset($_POST["submitted"])){
	require_once("/includes/mysql_connect.php");
	$pollname = $_POST["pollname"];
	if(isset($_POST["question"])) {
		$question = escape_data($_POST["question"]);
	}
	else {
		$question = FALSE;
	}
	if(isset($_POST["answer1"])){
	$answer1 = escape_data($_POST["answer1"]);
	}
	else {
		$answer1 = FALSE;
	}
	if(isset($_POST["answer2"])){
		$answer2 = escape_data($_POST["answer2"]);
	}
	else {
		$answer2 = FALSE;
	}
	if(isset($_POST["answer3"])) {
		$answer3 = escape_data($_POST["answer3"]);
	}
	else {
		$answer3 = FALSE;
	}
	if(isset($_POST["answer4"])){
		$answer4 = escape_data($_POST["answer4"]);
	}
	else {
		$answer4 = FALSE;
	}
	if(isset($_POST["answer5"])){
		$answer5 = escape_data($_POST["answer5"]);
	}
	else {
		$answer5 = FALSE;
	}
	if(isset($_POST["answer6"])){
		$answer6 = escape_data($_POST["answer6"]);
	}
	else {
		$answer6 = FALSE;
	}
	
	if($question && $answer1 && $answer2 && $answer3 && $answer4 && $answer5 && $answer6){
		$query = "INSERT INTO polls (group_name, data, type) VALUES ('$pollname', '$question', 'q')";
		$result = mysql_query($query) or trigger_error("Query: $query\n<br>MySQL Error:" .mysql_error());
		$query2 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer1', 'a', 1)";
		$result2 = mysql_query($query2) or trigger_error("Query: $query2\n<br>MySQL Error:" .mysql_error());
		$query3 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer2', 'a', 2)";
		$result3 = mysql_query($query3) or trigger_error("Query: $query3\n<br>MySQL Error:" .mysql_error());
		$query4 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer3', 'a', 3)";
		$result4 = mysql_query($query4) or trigger_error("Query: $query4\n<br>MySQL Error:" .mysql_error());
		$query5 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer4', 'a', 4)";
		$result5= mysql_query($query5) or trigger_error("Query: $query5\n<br>MySQL Error:" .mysql_error());
		$query6 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer5', 'a', 5)";
		$result6 = mysql_query($query6) or trigger_error("Query: $query6\n<br>MySQL Error:" .mysql_error());
		$query7 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer6', 'a', 6)";
		$result7 = mysql_query($query7) or trigger_error("Query: $query7\n<br>MySQL Error:" .mysql_error());
	}
	elseif($question && $answer1 && $answer2 && $answer3 && $answer4 && $answer5){
		$query = "INSERT INTO polls (group_name, data, type) VALUES ('$pollname', '$question', 'q')";
		$result = mysql_query($query) or trigger_error("Query: $query\n<br>MySQL Error:" .mysql_error());
		$query2 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer1', 'a', 1)";
		$result2 = mysql_query($query2) or trigger_error("Query: $query2\n<br>MySQL Error:" .mysql_error());
		$query3 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer2', 'a', 2)";
		$result3 = mysql_query($query3) or trigger_error("Query: $query3\n<br>MySQL Error:" .mysql_error());
		$query4 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer3', 'a', 3)";
		$result4 = mysql_query($query4) or trigger_error("Query: $query4\n<br>MySQL Error:" .mysql_error());
		$query5 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer4', 'a', 4)";
		$result5= mysql_query($query5) or trigger_error("Query: $query5\n<br>MySQL Error:" .mysql_error());
		$query6 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer5', 'a', 5)";
		$result6 = mysql_query($query6) or trigger_error("Query: $query6\n<br>MySQL Error:" .mysql_error());
	}
	elseif($question && $answer1 && $answer2 && $answer3 && $answer4) {
		$query = "INSERT INTO polls (group_name, data, type) VALUES ('$pollname', '$question', 'q')";
		$result = mysql_query($query) or trigger_error("Query: $query\n<br>MySQL Error:" .mysql_error());
		$query2 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer1', 'a', 1)";
		$result2 = mysql_query($query2) or trigger_error("Query: $query2\n<br>MySQL Error:" .mysql_error());
		$query3 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer2', 'a', 2)";
		$result3 = mysql_query($query3) or trigger_error("Query: $query3\n<br>MySQL Error:" .mysql_error());
		$query4 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer3', 'a', 3)";
		$result4 = mysql_query($query4) or trigger_error("Query: $query4\n<br>MySQL Error:" .mysql_error());
		$query5 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer4', 'a', 4)";
		$result5= mysql_query($query5) or trigger_error("Query: $query5\n<br>MySQL Error:" .mysql_error());
	}
	elseif($question && $answer1 && $answer2 && $answer3) {
		$query = "INSERT INTO polls (group_name, data, type) VALUES ('$pollname', '$question', 'q')";
		$result = mysql_query($query) or trigger_error("Query: $query\n<br>MySQL Error:" .mysql_error());
		$query2 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer1', 'a', 1)";
		$result2 = mysql_query($query2) or trigger_error("Query: $query2\n<br>MySQL Error:" .mysql_error());
		$query3 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer2', 'a', 2)";
		$result3 = mysql_query($query3) or trigger_error("Query: $query3\n<br>MySQL Error:" .mysql_error());
		$query4 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer3', 'a', 3)";
		$result4 = mysql_query($query4) or trigger_error("Query: $query4\n<br>MySQL Error:" .mysql_error());
	}
	elseif($question && $answer1 && $answer2) {
		$query = "INSERT INTO polls (group_name, data, type) VALUES ('$pollname', '$question', 'q')";
		$result = mysql_query($query) or trigger_error("Query: $query\n<br>MySQL Error:" .mysql_error());
		$query2 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer1', 'a', 1)";
		$result2 = mysql_query($query2) or trigger_error("Query: $query2\n<br>MySQL Error:" .mysql_error());
		$query3 = "INSERT INTO polls (group_name, data, type, a_id) VALUES ('$pollname', '$answer2', 'a', 2)";
		$result3 = mysql_query($query3) or trigger_error("Query: $query3\n<br>MySQL Error:" .mysql_error());
	}
	else {
		echo "A aparut o eroare";
	}
	mysql_close();
}
		
?>
<form action="poll.php" method="post">
<fieldset>
<table>
<tr><td><p class="text2">Poll Name: </p></td><td><input type="text" name="pollname" /></td></tr>
<tr><td><p class="text2">Question: </p></td><td><input type="text" name="question" size="50"/></td></tr>
<tr><td><p class="text2">Answer1: </p></td><td><input type="text" name="answer1" /></td></tr>
<tr><td><p class="text2">Answer2: </p></td><td><input type="text" name="answer2" /></td></tr>
<tr><td><p class="text2">Answer3: </p></td><td><input type="text" name="answer3" /></td></tr>
<tr><td><p class="text2">Answer4: </p></td><td><input type="text" name="answer4" /></td></tr>
<tr><td><p class="text2">Answer5: </p></td><td><input type="text" name="answer5" /></td></tr>
<tr><td><p class="text2">Answer6: </p></td><td><input type="text" name="answer6" /></td></tr>
</table>
<input type="submit" value="Create" name="submit" />
<input type="hidden" value="TRUE" name="submitted" />
</form>
</fieldset>
<?php
require_once("/includes/mysql_connect.php");
$query8 = "SELECT DISTINCT group_name FROM polls";
$result8 = @mysql_query($query8);
if ($result8) //Daca totul a mers bine afiseaza inregistrarile
{
	echo "<table>";
	while ($row = mysql_fetch_array($result8, MYSQL_ASSOC))
	{
		echo "<tr><td>$row[group_name]</td></tr>";
	}
	echo "</table>";
}
mysql_close();
?>
<?php
include_once("end.php");
?>

